package com.xcjw.com.Activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadmoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.xcjw.com.Base.Myapplication;
import com.xcjw.com.Bean.CarBean;
import com.xcjw.com.Bean.CarResponse;
import com.xcjw.com.Bean.JiabanResponse;
import com.xcjw.com.Bean.LoginUser;
import com.xcjw.com.Bean.MeetIngResponse;
import com.xcjw.com.Http.HttpUrl;
import com.xcjw.com.R;
import com.xcjw.com.Utils.FileUtils;
import com.xcjw.com.Utils.JsonUtil;
import com.xcjw.com.Utils.StatusBarUtil;
import com.xcjw.com.Utils.StatusbarUtils;
import com.xcjw.com.Utils.TimeFormatUtils;
import com.xcjw.com.Utils.ToastUtils;
import com.xcjw.com.View.MyListview;
import com.xcjw.com.View.ObservableScrollView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;

/**
 * @packname com.xcjw.com.Activity
 * @filename CarActivity
 * @date on 2018/11/21 14:43
 *****/
public class CarActivity extends AppCompatActivity implements ObservableScrollView.OnObservableScrollViewListener, View.OnClickListener {
      @BindView(R.id.tv_main_topContent)
      RelativeLayout tvMainTopContent;
      @BindView(R.id.listview)
      MyListview listview;
      @BindView(R.id.fabu_button)
      RelativeLayout fabuButton;
      @BindView(R.id.sv_main_content)
      ObservableScrollView svMainContent;
      @BindView(R.id.smart)
      SmartRefreshLayout smart;
      @BindView(R.id.iv_header_left)
      ImageView ivHeaderLeft;
      @BindView(R.id.tv_header_title)
      TextView tvHeaderTitle;
      @BindView(R.id.iv_header_img)
      TextView ivHeaderImg;
      @BindView(R.id.relayout)
      RelativeLayout relayout;
      @BindView(R.id.ll_header_content)
      LinearLayout llHeaderContent;
      @BindView(R.id.kongtext)
      TextView kongtext;
      private ObservableScrollView mObservableScrollView;
      private TextView mImageView;
      private LinearLayout mHeaderContent;
      private int mHeight;
      private int page;
      private LoginUser.ContentBean user;
      private List<CarResponse.ContentBean> threelist;
      private List<JiabanResponse.ContentBean> twolist;
      private List<MeetIngResponse.ContentBean> onelist;
      private int start;
      private OneAdapter adapter1;
      private TwoAdapter adapter2;
      private int start1;
      private int flags;
      private ThreeAdapter adapter3;

      @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            StatusbarUtils.enableTranslucentStatusbar(this);
            StatusBarUtil.setStatusBarDarkTheme(this, true);
            setContentView(R.layout.car_activity);
            ButterKnife.bind(this);
            user = (LoginUser.ContentBean) FileUtils.getObject(CarActivity.this, "loginUser");
            int result = 0;
            int resourceId = this.getResources().getIdentifier("status_bar_height", "dimen", "android");
            flags = getIntent().getFlags();
            Myapplication.getInstance().addActivity(this);
            fabuButton.setOnClickListener(this);
            ivHeaderLeft.setOnClickListener(this);
            onelist = new ArrayList<>();
            twolist = new ArrayList<>();
            threelist = new ArrayList<>();
            if (user.getIsShow() == 0) {
                  fabuButton.setVisibility(View.INVISIBLE);
                  //look.setVisibility(View.INVISIBLE);
            } else {
                  fabuButton.setVisibility(View.VISIBLE);
                  //look.setVisibility(View.VISIBLE);
            }
            // smart.autoRefresh();
            if (resourceId > 0) {
                  result = this.getResources().getDimensionPixelSize(resourceId);
            }
            llHeaderContent.setPadding(0, result, 0, 0);
            mObservableScrollView = (ObservableScrollView) findViewById(R.id.sv_main_content);
            mHeaderContent = (LinearLayout) findViewById(R.id.ll_header_content);
            ViewTreeObserver viewTreeObserver = tvMainTopContent.getViewTreeObserver();
            viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                  @Override
                  public void onGlobalLayout() {
                        tvMainTopContent.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        tvMainTopContent.getHeight();
                        //注册滑动监听
                        mObservableScrollView.setOnObservableScrollViewListener(CarActivity.this);
                  }
            });
            fabuButton.setOnClickListener(this);
            listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                  @Override
                  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                        switch (flags) {
                              case 1:
                                    if (onelist.get(position).getCheckStatus() == 0 || onelist.get(position).getCheckStatus()== 2) {
                                          Intent intent = new Intent(CarActivity.this,AddMeetActivity.class);
                                          intent.putExtra("detail",onelist.get(position));
                                          startActivity(intent);
                                    } else {
                                          return;
                                    }
                                    break;
                              case 2:
//                                    if (twolist.get(position).getCheckStates() == 0 || twolist.get(position).getCheckStates()== 2) {
//                                          Intent intent = new Intent(CarActivity.this,AddWorkActivity.class);
//                                          intent.putExtra("detail",twolist.get(position));
//                                          startActivity(intent);
//                                    } else {
//                                          return;
//                                    }
//                                    break;
                              case 3:
                                    if (threelist.get(position).getCheckStates() == 0 || threelist.get(position).getCheckStates()== 2) {
                                          Intent intent = new Intent(CarActivity.this,AddCarActivity.class);
                                          intent.putExtra("detail",threelist.get(position));
                                          startActivity(intent);
                                    } else {
                                          return;
                                    }
                                    break;
                        }
                  }
            });
            if (flags == 1) {
                  tvMainTopContent.setBackgroundResource(R.drawable.hys_top);
                  tvHeaderTitle.setVisibility(View.INVISIBLE);
                  fabuButton.setBackground(getResources().getDrawable(R.drawable.meeting_button_shape));
                  adapter1 = new OneAdapter();
                  listview.setAdapter(adapter1);
                  smart.setOnRefreshListener(new OnRefreshListener() {
                        @Override
                        public void onRefresh(RefreshLayout refreshlayout) {
                              start = 0;
                              onelist.clear();
                              getDate();
                              smart.setEnableLoadmore(true);
                        }
                  });

                  smart.setOnLoadmoreListener(new OnLoadmoreListener() {
                        @Override
                        public void onLoadmore(RefreshLayout refreshlayout) {
                              if (smart.isEnableLoadmore()) {
                                    start++;
                                    lodamore();
                              }
                        }
                  });


            } else if (flags == 2) {
                  tvMainTopContent.setBackgroundResource(R.drawable.yc_top);
                  tvHeaderTitle.setVisibility(View.INVISIBLE);
                  fabuButton.setBackground(getResources().getDrawable(R.drawable.jiaban_button_shape));
                  adapter2 = new TwoAdapter();
                  listview.setAdapter(adapter2);
                  adapter2.notifyDataSetChanged();
                  smart.setOnRefreshListener(new OnRefreshListener() {
                        @Override
                        public void onRefresh(RefreshLayout refreshlayout) {
                              start1 = 0;
                              twolist.clear();
                              getDate1();
                              smart.setEnableLoadmore(true);
                        }
                  });

                  smart.setOnLoadmoreListener(new OnLoadmoreListener() {
                        @Override
                        public void onLoadmore(RefreshLayout refreshlayout) {
                              if (smart.isEnableLoadmore()) {
                                    start1++;
                                    lodamore1();
                              }

                        }
                  });
            } else {
                  tvMainTopContent.setBackgroundResource(R.drawable.yc_top2);
                  tvHeaderTitle.setVisibility(View.INVISIBLE);
                  fabuButton.setBackground(getResources().getDrawable(R.drawable.car_button_shape));
                  adapter3 = new ThreeAdapter();
                  listview.setAdapter(adapter3);
                  smart.setOnRefreshListener(new OnRefreshListener() {
                        @Override
                        public void onRefresh(RefreshLayout refreshlayout) {
                              page = 0;
                              threelist.clear();
                              getDate2();
                              smart.setEnableLoadmore(true);
                        }
                  });

                  smart.setOnLoadmoreListener(new OnLoadmoreListener() {
                        @Override
                        public void onLoadmore(RefreshLayout refreshlayout) {
                              if (smart.isEnableLoadmore()) {
                                    page++;
                                    lodamore2();
                              }


                        }
                  });
            }
      }

      private void lodamore2() {
            final CarBean bea = new CarBean();
            bea.setId(user.getId());
            bea.setNumPage(page);
            OkHttpUtils.post(HttpUrl.Url + HttpUrl.UseCAR).upJson(JsonUtil.tojson(bea)).execute(new StringCallback() {
                  @Override
                  public void onSuccess(String s, Call call, Response response) {
                        if (response.code() == 200) {
                              CarResponse bean = JsonUtil.parseJsonToBean(s, CarResponse.class);
                              if (bean.getCode().equals("0")) {
                                    if (bean.getContent().size() > 0) {
                                          threelist.addAll(bean.getContent());
                                          adapter2.notifyDataSetChanged();
                                          smart.finishLoadmore();
                                    } else {
                                          smart.finishLoadmore();
                                          smart.setEnableLoadmore(false);
                                          ToastUtils.shorttoast(CarActivity.this, "没有更多了");
                                    }
                              } else {
                                    smart.finishLoadmore();
                                    smart.setEnableLoadmore(false);
                                    ToastUtils.shorttoast(CarActivity.this, bean.getMessage());
                              }

                        } else {
                              smart.finishLoadmore();
                              ToastUtils.shorttoast(CarActivity.this, "网络繁忙，稍后重试");
                        }
                  }

                  @Override
                  public void onError(Call call, Response response, Exception e) {
                        smart.finishLoadmore();
                        ToastUtils.shorttoast(CarActivity.this, "网络繁忙，稍后重试");
                  }
            });

      }

      @Override
      public void onObservableScrollViewListener(int l, int t, int oldl, int oldt) {
            if (t <= mHeight) {
                  //顶部图处于最顶部，标题栏透明
                  mHeaderContent.setBackgroundColor(Color.argb(0, 48, 63, 159));
                  tvHeaderTitle.setVisibility(View.GONE);
            } else if (t > mHeight) {
                  tvHeaderTitle.setVisibility(View.VISIBLE);
                  if (flags == 1) {
                        tvHeaderTitle.setText("会议申请");
                  } else if (flags == 2) {
                        tvHeaderTitle.setText("加班申请");
                  } else {
                        tvHeaderTitle.setText("用车申请");
                  }
                  //过顶部图区域，标题栏定色
                  mHeaderContent.setBackgroundColor(getResources().getColor(R.color.blue));
            }
      }


      public void getDate() {
            CarBean bean = new CarBean();
            bean.setId(user.getId());
            bean.setNumPage(page);
            OkHttpUtils.get(HttpUrl.Url + HttpUrl.querymeeting).params("senderId", user.getId()).params("start", start).execute(new StringCallback() {
                  @Override
                  public void onSuccess(String s, Call call, Response response) {
                        if (response.code() == 200) {
                              MeetIngResponse bean = JsonUtil.parseJsonToBean(s, MeetIngResponse.class);
                              if (bean.getCode().equals("0")) {
                                    if (bean.getContent().size() > 0) {
                                          onelist.addAll(bean.getContent());
                                          adapter1.notifyDataSetChanged();
                                          smart.finishRefresh();
                                    } else {
                                          smart.finishRefresh();
                                          ToastUtils.shorttoast(CarActivity.this, "没有数据");
                                    }
                              } else {
                                    smart.finishRefresh();
                                    ToastUtils.shorttoast(CarActivity.this, "网络繁忙，稍后重试");
                              }

                        } else {
                              smart.finishRefresh();
                              ToastUtils.shorttoast(CarActivity.this, "网络繁忙，稍后重试");
                        }
                        if (onelist.size() > 0) {
                              kongtext.setVisibility(View.GONE);
                        } else {
                              kongtext.setVisibility(View.VISIBLE);
                        }
                  }

                  @Override
                  public void onError(Call call, Response response, Exception e) {
                        smart.finishRefresh();
                  }
            });
      }

      public void lodamore() {
            OkHttpUtils.get(HttpUrl.Url + HttpUrl.querymeeting).params("senderId", user.getId()).params("start", start).execute(new StringCallback() {
                  @Override
                  public void onSuccess(String s, Call call, Response response) {

                        if (response.code() == 200) {
                              MeetIngResponse bean = JsonUtil.parseJsonToBean(s, MeetIngResponse.class);
                              if (bean.getCode().equals("0")) {
                                    if (bean.getContent().size() > 0) {
                                          onelist.addAll(bean.getContent());
                                          adapter1.notifyDataSetChanged();
                                          smart.finishLoadmore();
                                    } else {
                                          smart.finishLoadmore();
                                          smart.setEnableLoadmore(false);
                                          ToastUtils.shorttoast(CarActivity.this, "没有更多了");
                                    }
                              } else {
                                    smart.finishLoadmore();
                                    smart.setEnableLoadmore(false);
                                    ToastUtils.shorttoast(CarActivity.this, bean.getMessage());
                              }

                        } else {
                              smart.finishLoadmore();
                              ToastUtils.shorttoast(CarActivity.this, "网络繁忙，稍后重试");
                        }


                  }

                  @Override
                  public void onError(Call call, Response response, Exception e) {
                        smart.finishLoadmore();
                        ToastUtils.shorttoast(CarActivity.this, "网络繁忙，稍后重试");
                  }
            });
      }

      public void lodamore1() {
            OkHttpUtils.get(HttpUrl.Url + HttpUrl.querywork).params("uid", user.getId()).params("start", start1).execute(new StringCallback() {
                  @Override
                  public void onSuccess(String s, Call call, Response response) {
                        if (response.code() == 200) {
                              JiabanResponse bean = JsonUtil.parseJsonToBean(s, JiabanResponse.class);


                              if (bean.getCode().equals("0")) {
                                    if (bean.getContent().size() > 0) {
                                          twolist.addAll(bean.getContent());
                                          adapter2.notifyDataSetChanged();
                                          smart.finishLoadmore();
                                    } else {
                                          smart.finishLoadmore();
                                          smart.setEnableLoadmore(false);
                                          ToastUtils.shorttoast(CarActivity.this, "没有更多了");
                                    }
                              } else {
                                    smart.finishLoadmore();
                                    smart.setEnableLoadmore(false);
                                    ToastUtils.shorttoast(CarActivity.this, bean.getMessage());
                              }

                        } else {
                              smart.finishLoadmore();
                              ToastUtils.shorttoast(CarActivity.this, "网络繁忙，稍后重试");
                        }


                  }

                  @Override
                  public void onError(Call call, Response response, Exception e) {
                        smart.finishLoadmore();
                        ToastUtils.shorttoast(CarActivity.this, "网络繁忙，稍后重试");
                  }
            });
      }

      public void getDate1() {
            OkHttpUtils.get(HttpUrl.Url + HttpUrl.querywork).
                      params("uid", user.getId()).
                      params("start", start1).
                      execute(new StringCallback() {
                                    @Override
                                    public void onSuccess(String s, Call call, Response response) {

                                          if (response.code() == 200) {
                                                JiabanResponse bean = JsonUtil.parseJsonToBean(s, JiabanResponse.class);

                                                if (bean.getCode().equals("0")) {
                                                      if (bean.getContent().size() > 0) {
                                                            twolist.addAll(bean.getContent());
                                                            adapter2.notifyDataSetChanged();
                                                            smart.finishRefresh();
                                                      } else {
                                                            smart.finishRefresh();
                                                            ToastUtils.shorttoast(CarActivity.this, "没有数据");
                                                      }
                                                } else {
                                                      smart.finishRefresh();
                                                      ToastUtils.shorttoast(CarActivity.this, bean.getMessage());
                                                }
                                          } else {
                                                smart.finishRefresh();
                                                ToastUtils.shorttoast(CarActivity.this, "没有数据");
                                          }
                                          if (twolist.size() > 0) {
                                                kongtext.setVisibility(View.GONE);
                                          } else {
                                                kongtext.setVisibility(View.VISIBLE);
                                          }
                                    }

                                    @Override
                                    public void onError(Call call, Response response, Exception e) {
                                          smart.finishRefresh();
                                          ToastUtils.shorttoast(CarActivity.this, "网络繁忙，稍后重试");
                                          if (twolist.size() > 0) {
                                                kongtext.setVisibility(View.GONE);
                                          } else {
                                                kongtext.setVisibility(View.VISIBLE);
                                          }

                                    }
                              }

                      );
      }

      public void getDate2() {
            final CarBean bea = new CarBean();
            bea.setId(user.getId());
            bea.setNumPage(page);
            OkHttpUtils.post(HttpUrl.Url + HttpUrl.UseCAR).upJson(JsonUtil.tojson(bea)).execute(new StringCallback() {
                  @Override
                  public void onSuccess(String s, Call call, Response response) {
                        if (response.code() == 200) {
                              CarResponse bean = JsonUtil.parseJsonToBean(s, CarResponse.class);
                              if (bean.getCode().equals("0")) {
                                    if (bean.getContent().size() > 0) {
                                          threelist.addAll(bean.getContent());
                                          adapter3.notifyDataSetChanged();
                                          smart.finishRefresh();
                                    } else {
                                          smart.finishRefresh();
                                          ToastUtils.shorttoast(CarActivity.this, "没有数据");
                                    }

                              } else {
                                    smart.finishRefresh();
                                    ToastUtils.shorttoast(CarActivity.this, bean.getMessage());
                              }

                        } else {
                              smart.finishRefresh();
                              ToastUtils.shorttoast(CarActivity.this, "网络繁忙，稍后重试");
                        }
                        if (threelist.size() > 0) {
                              kongtext.setVisibility(View.GONE);
                        } else {
                              kongtext.setVisibility(View.VISIBLE);
                        }
                  }

                  @Override
                  public void onError(Call call, Response response, Exception e) {
                        smart.finishRefresh();
                        ToastUtils.shorttoast(CarActivity.this, "网络繁忙，稍后重试");
                        if (threelist.size() > 0) {
                              kongtext.setVisibility(View.GONE);
                        } else {
                              kongtext.setVisibility(View.VISIBLE);
                        }
                  }
            });
      }

      @Override
      public void onClick(View v) {
            switch (v.getId()) {
                  case R.id.fabu_button:
                        if (flags == 1) {
                              startActivity(new Intent(CarActivity.this, AddMeetActivity.class));
                        } else if (flags == 2) {
                              startActivity(new Intent(CarActivity.this, AddWorkActivity.class));
                        } else {
                              Intent carintent = new Intent(CarActivity.this, AddCarActivity.class);
                              carintent.setFlags(0);
                              startActivity(carintent);
                        }
                        break;
                  case R.id.iv_header_left:
                        onBackPressed();
                        break;
            }
      }

      class OneAdapter extends BaseAdapter {

            @Override
            public int getCount() {
                  return onelist.size() > 0 ? onelist.size() : 0;
            }

            @Override
            public Object getItem(int position) {
                  return onelist.get(position);
            }

            @Override
            public long getItemId(int position) {
                  return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                  OneHolder holder = null;
                  if (convertView == null) {
                        holder = new OneHolder();
                        convertView = View.inflate(CarActivity.this, R.layout.item_first, null);
                        holder.state = (TextView) convertView.findViewById(R.id.state);
                        holder.shijianduan = (TextView) convertView.findViewById(R.id.shijianduan);
                        holder.date = (TextView) convertView.findViewById(R.id.date);
                        holder.person = (TextView) convertView.findViewById(R.id.person);
                        holder.mudidi = (TextView) convertView.findViewById(R.id.mudidi);
                        holder.cehxing = (TextView) convertView.findViewById(R.id.cehxing);
                        holder.refuse = (TextView) convertView.findViewById(R.id.refuse);
                        holder.view = (LinearLayout) convertView.findViewById(R.id.view);
                        convertView.setTag(holder);
                  } else {
                        holder = (OneHolder) convertView.getTag();
                  }
                  switch (onelist.get(position).getCheckStatus()) {
                        case -1:
                              holder.state.setText("已批准");
                              holder.view.setVisibility(View.GONE);
                              holder.state.setTextColor(getResources().getColor(R.color.login_white));
                              break;
                        case 0:
                              holder.state.setText("未提交");
                              holder.view.setVisibility(View.GONE);
                              holder.state.setTextColor(getResources().getColor(R.color.caryellow));
                              break;
                        case 1:
                              holder.state.setText("待批准");
                              holder.view.setVisibility(View.GONE);
                              holder.state.setTextColor(getResources().getColor(R.color.sss));
                              break;
                        case 2:
                              holder.state.setText("未通过");
                              holder.view.setVisibility(View.VISIBLE);
                              holder.refuse.setText(onelist.get(position).getAdvice() == null ? "": onelist.get(position).getAdvice());
                              holder.state.setTextColor(getResources().getColor(R.color.red));
                              break;
                  }
                  holder.date.setText(TimeFormatUtils.ms2DateOnlyDay(onelist.get(position).getReserveDate()));
                  holder.person.setText(onelist.get(position).getPlace());
                  holder.shijianduan.setText(onelist.get(position).getStartTime() + "-" + onelist.get(position).getEndTime());
                  holder.mudidi.setText(onelist.get(position).getContent());
                  holder.cehxing.setText(onelist.get(position).getNeed());
                  return convertView;
            }
      }

      class TwoAdapter extends BaseAdapter {

            @Override
            public int getCount() {
                  return twolist.size() > 0 ? twolist.size() : 0;
            }

            @Override
            public Object getItem(int position) {
                  return twolist.get(position);
            }

            @Override
            public long getItemId(int position) {
                  return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                  TwoHolder holder = null;
                  if (convertView == null) {
                        holder = new TwoHolder();
                        convertView = View.inflate(CarActivity.this, R.layout.item_secend, null);
                        holder.state = (TextView) convertView.findViewById(R.id.state);
                        holder.date = (TextView) convertView.findViewById(R.id.date);
                        holder.person = (TextView) convertView.findViewById(R.id.person);
                        holder.mudidi = (TextView) convertView.findViewById(R.id.mudidi);
                        holder.cehxing = (TextView) convertView.findViewById(R.id.cehxing);
                        holder.reason = (TextView) convertView.findViewById(R.id.reason);
                        convertView.setTag(holder);
                  } else {
                        holder = (TwoHolder) convertView.getTag();
                  }
                  switch (twolist.get(position).getCheckStates()) {
                        case -1:
                              holder.state.setText("已批准");
                              holder.state.setTextColor(getResources().getColor(R.color.login_white));
                              break;
                        case 0:
                              holder.state.setText("未提交");
                              holder.state.setTextColor(getResources().getColor(R.color.caryellow));
                              break;
                        case 1:
                              holder.state.setText("待批准");
                              holder.state.setTextColor(getResources().getColor(R.color.sss));
                              break;
                        case 2:
                              holder.state.setText("一级审核未通过");
                              holder.state.setTextColor(getResources().getColor(R.color.red));
                              break;
                        case 3:
                              holder.state.setText("一级审核通过");
                              holder.state.setTextColor(getResources().getColor(R.color.nnn));
                              break;
                  }
                  holder.date.setText(twolist.get(position).getWorkOevertimeInfo().getWorkovertime());
                  if (twolist.get(position).getWorkOevertimeInfo() != null) {
                        holder.date.setText(twolist.get(position).getWorkOevertimeInfo().getWorkovertime() + "");
                        holder.person.setText(twolist.get(position).getWorkOevertimeInfo().getWorkcontent() + "");
                        holder.mudidi.setText(twolist.get(position).getWorkOevertimeInfo().getWorkpersonnel() + "");
                  }
                  holder.reason.setText(twolist.get(position).getWorkOevertimeInfo().getNote() + "");
                  holder.cehxing.setText(twolist.get(position).getDepartName());
                  return convertView;
            }
      }

      class ThreeAdapter extends BaseAdapter {

            @Override
            public int getCount() {
                  return threelist.size() > 0 ? threelist.size() : 0;
            }

            @Override
            public Object getItem(int position) {
                  return threelist.get(position);
            }

            @Override
            public long getItemId(int position) {
                  return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                  ThreeHolder holder = null;
                  if (convertView == null) {
                        holder = new ThreeHolder();
                        convertView = View.inflate(CarActivity.this, R.layout.item_three, null);
                        holder.state = (TextView) convertView.findViewById(R.id.state);
                        holder.depart = (TextView) convertView.findViewById(R.id.depart);
                        holder.tuihuireason = (TextView) convertView.findViewById(R.id.tuihuireason);
                        holder.tuihui = (LinearLayout) convertView.findViewById(R.id.tuihui);
                        holder.date = (TextView) convertView.findViewById(R.id.date);
                        holder.person = (TextView) convertView.findViewById(R.id.person);
                        holder.mudidi = (TextView) convertView.findViewById(R.id.mudidi);
                        holder.cehxing = (TextView) convertView.findViewById(R.id.cehxing);
                        holder.reason = (TextView) convertView.findViewById(R.id.reason);
                        convertView.setTag(holder);
                  } else {
                        holder = (ThreeHolder) convertView.getTag();
                  }
                  switch (threelist.get(position).getCheckStates()) {
                        case -1:
                              holder.state.setText("已批准");
                              holder.tuihui.setVisibility(View.GONE);
                              holder.state.setTextColor(getResources().getColor(R.color.login_white));
                              break;
                        case 0:
                              holder.state.setText("未提交");
                              holder.tuihui.setVisibility(View.GONE);
                              holder.state.setTextColor(getResources().getColor(R.color.caryellow));
                              break;
                        case 1:
                              holder.state.setText("待批准");
                              holder.tuihui.setVisibility(View.GONE);
                              holder.state.setTextColor(getResources().getColor(R.color.sss));
                              break;
                        case 2:
                              holder.state.setText("未通过");
                              holder.tuihui.setVisibility(View.VISIBLE);
                              if (TextUtils.isEmpty(threelist.get(position).getAdvice())) {
                                    holder.tuihuireason.setText("");
                              } else {
                                    holder.tuihuireason.setText(threelist.get(position).getAdvice());
                              }
                              holder.state.setTextColor(getResources().getColor(R.color.red));
                              break;
                  }
                  holder.date.setText(TimeFormatUtils.ms2DateOnlyDay(threelist.get(position).getFillInFormTime()));
                  holder.depart.setText(threelist.get(position).getDepartName());
                  holder.person.setText(threelist.get(position).getNumberOfPeople() + "");
                  holder.mudidi.setText(threelist.get(position).getDestination());
                  holder.reason.setText(threelist.get(position).getMainContent());
                  holder.cehxing.setText(threelist.get(position).getCarTypeName());
                  return convertView;
            }
      }

      class OneHolder {
            TextView state, date, person, mudidi, cehxing, shijianduan,refuse;
            LinearLayout view;
      }

      class TwoHolder {
            TextView state, date, person, mudidi, cehxing, reason;
      }

      class ThreeHolder {
            TextView state, date, person, mudidi, cehxing, reason, depart, tuihuireason;
            LinearLayout tuihui;
      }

      @Override
      protected void onResume() {
            super.onResume();
            smart.autoRefresh();
      }
}